package com.example.exercise.app.feedbackreply.controller;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

import com.example.exercise.app.feedbackreply.dto.request.AppReplyRequest;
import com.example.exercise.app.feedbackreply.dto.response.AppReplyResponse;
import com.example.exercise.app.feedbackreply.service.AppReplyService;
import com.example.exercise.core.base.dto.BaseResponse;

@RestController
@RequestMapping("/appReply")
//@Api(description = "评论回复")
public class AppReplyController {

	@Resource
	private AppReplyService appReplyService;

//	@ApiOperation(value = "查询回复（支持查询多条，分页查询列表）", notes = "查询回复（必输为：id）")
	@RequestMapping(value = "findByWhere", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE })
	public BaseResponse<Map<String, Object>> findByWhere(AppReplyRequest appReplyRequest){
		BaseResponse<Map<String, Object>> baseResponse = new BaseResponse<>();
		if(appReplyRequest.getCurrentPage() == null || appReplyRequest.getCurrentPage() == 0)appReplyRequest.setCurrentPage(1);
		if(appReplyRequest.getPageSize() == null || appReplyRequest.getPageSize() == 0)appReplyRequest.setPageSize(20);
		int count = appReplyService.getCountByWhere(appReplyRequest);
		List<AppReplyResponse> list = appReplyService.findByWhere(appReplyRequest);
		Map<String, Object> map = new HashMap<>();
		map.put("count",count);
		map.put("list",list);
		baseResponse.ok(map);
		return baseResponse;
	}

//	@ApiOperation(value = "添加回复，给评论回复", notes = "添加回复(必输：id，replyuserId，discussId，context)")
	@RequestMapping(value = "insertAppReply", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
	public BaseResponse<Object> insertAppReply(@RequestBody AppReplyRequest appReplyRequest, @RequestParam Integer userId,@RequestParam String token){
		BaseResponse<Object> baseResponse = new BaseResponse<>();
		int count = appReplyService.insertAppReply(appReplyRequest);
		if(count > 0){
			baseResponse.ok();
		}else{
			baseResponse.setCode(-11);
			baseResponse.setMsg("添加数据失败");
		}
		return baseResponse;
	}

//	@ApiOperation(value = "删除一条回复", notes = "删除一条回复（根据回复ID主键删除）")
	@RequestMapping(value = "deleteById", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE })
	public BaseResponse<Object> deleteById(@RequestParam Integer id, @RequestParam Integer userId,@RequestParam String token){
		BaseResponse<Object> baseResponse = new BaseResponse<>();
		int count = appReplyService.deleteById(id);
		if(count > 0){
			baseResponse.ok();
		}else{
			baseResponse.setCode(-11);
			baseResponse.setMsg("添加数据失败");
		}
		return baseResponse;
	}

}